package service;

import java.sql.SQLException;
import java.util.List;

import org.apache.commons.dbutils.QueryRunner;

import util.C3P0Util;

import dao.PetDaoImpl;
import domain.Owner;
import domain.Pet;

public class PetServiceImpl {
	//创建PetDaoImpl对象
	PetDaoImpl petDao = new PetDaoImpl();
	
	/**
	 * 查询所有宠物信息
	 * @return
	 */
	public List<Pet> findAllPets(){
		try {
			return petDao.findAllPets();
		} catch (SQLException e) {
			e.printStackTrace();
		}
		return null;
	}
	
	/**
	 * 
	 * @param pet
	 */
	public void addPet(Pet pet){
		try {
			petDao.addPet(pet);
		} catch (SQLException e) {
			e.printStackTrace();
		}
	}
	
	/**
	 * 通过宠物id查找宠物信息
	 * @param id
	 * @return
	 */
	public Pet findPetById(String petid) {
		try {
			return petDao.findPetById(petid);
		} catch (SQLException e) {
			e.printStackTrace();
		}
		return null;
	}
	/**
	 * 更新宠物信息
	 * @param pet
	 */
	public void updatePet(Pet pet) {
		try {
			petDao.updatePet(pet);
		} catch (SQLException e) {
			e.printStackTrace();
		}
	}
	/**
	 * 通过宠物id删除宠物信息
	 * @param id
	 * @return
	 */
	public void deletePetById(String petid) {
		try {
			 petDao.deletePetById(petid);
		} catch (SQLException e) {
			e.printStackTrace();
		}
	}
	/**
	 * 通过petId查找宠物主人信息
	 * @param petId
	 * @throws SQLException
	 */
	public Owner findOwnerByPetId(String petId) {
		try {
			return petDao.findOwnerByPetId(petId);
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return null;
	}
	/**
	 * 
	 * @param petId
	 * @param petName
	 * @param category
	 * @param petBirthday
	 * @param ownerId
	 * @param doctorId
	 * @return
	 */
	public List<Pet> findPetByConditions(String petId, String petName,
			String petSpecies, String petBirthday, String ownerId, String doctorId) {
		try {
			return petDao.findPetByConditions(petId, petName, petSpecies, petBirthday, ownerId, doctorId);
		} catch (SQLException e) {
			e.printStackTrace();
		}
		return null;
	}
	

	
	
	
}
